package com.ideheima.zuoye.zuoye1;

import java.io.Serializable;

class Result<T> implements Serializable {
    /*

     */
    private Integer code;
    private String msg;
    private T data;

    // 创建一个成功的Result对象
    //  T为泛型参数，结果对象可以是任意类型的数据
    //最后返回一个Result对象
    public static <T> Result<T> success() {
        Result<T> result = new Result<T>();
        result.code = 1;
        return result;
    }

    //定义一个泛型的方法，返回值和参数类型一致，

    public static <T> Result<T> success(T object) {
        Result<T> result = new Result<T>();
        result.data = object;
        result.code = 1;
        return result;
    }

    public static <T> Result<T> error(String msg) {
        Result result = new Result();
        result.msg = msg;
        result.code = 0;
        return result;
    }
}

